﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ScreenMonitor.Common.Objects;
using ScreenMonitor.Common;
using ScreenMonitor.ServerLib;

namespace ServerUI
{
    public partial class ScreenViewerFull : Form
    {

        public Image img
        {
            get { return pictureBox1.Image; }
            set { pictureBox1.Image = value; }
        }

        private Point LastMouseMovePos = new Point();

        public bool IsControlMode { get; set; }

        private ScreenViewerMini ViewMini;

        public ScreenViewerFull(ScreenViewerMini mini)
        {
            InitializeComponent();
            ViewMini = mini;
        }

        private void ScreenViewerFull_Load(object sender, EventArgs e)
        {

        }

        private void ScreenViewerFull_MouseLeave(object sender, EventArgs e)
        {

        }

        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            Hide();
        }

        private void ScreenViewerFull_Shown(object sender, EventArgs e)
        {
            string t = this.Size.Width.ToString() + "*" + this.Size.Height.ToString();
            ViewMini.Client.SendImgSize = this.Size;
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            LastMouseMovePos = new Point(e.X, e.Y);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (!IsControlMode)
                return;
            ViewMini.Client.DoMouseEvent(MouseEventType.MouseMove, LastMouseMovePos);
        }

        private void pictureBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (!IsControlMode)
                return;
            ViewMini.Client.DoMouseEvent(MouseEventType.MouseDoubleClick, e.Location);
        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (!IsControlMode)
                return;
            MouseEventType EveType = MouseEventType.MouseLeftDown;
            switch (e.Button)
            {
                case MouseButtons.Left:
                    EveType = MouseEventType.MouseLeftDown;
                    break;
                case MouseButtons.Right:
                    EveType = MouseEventType.MouseRightDown;
                    break;
            }
            ViewMini.Client.DoMouseEvent(EveType, e.Location);
        }

        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            if (!IsControlMode)
                return;
            ViewMini.Client.DoMouseEvent(MouseEventType.MouseDoubleClick, e.Location);
        }

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            if (!IsControlMode)
                return;
            MouseEventType EveType = MouseEventType.MouseLeftUp;
            switch (e.Button)
            {
                case MouseButtons.Left:
                    EveType = MouseEventType.MouseLeftUp;
                    break;
                case MouseButtons.Right:
                    EveType = MouseEventType.MouseRightUp;
                    break;
            }
            ViewMini.Client.DoMouseEvent(EveType, e.Location);
        }

        private void ScreenViewerFull_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Escape)
            {
                if (!IsControlMode)
                    return;
                ViewMini.Client.DoKeyboardEvent(KeyBoardType.Key_Down, e.KeyCode);
            }
        }

        private void ScreenViewerFull_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Hide();
            }
            else
            {
                if (!IsControlMode)
                    return;
                ViewMini.Client.DoKeyboardEvent(KeyBoardType.Key_Up, e.KeyCode);
            }
        }

    }
}
